package com.module_live.fragment.coachstudy;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.herewhite.sdk.Room;
import com.herewhite.sdk.WhiteBroadView;
import com.lib.fastkit.db.shared_prefrences.SharedPreferenceManager;
import com.lib.ui.fragment.BaseAppFragment;
import com.module_live.R;
import com.module_live.R2;

import butterknife.BindView;

@SuppressLint("ValidFragment")
public class StudyWhiteBroadFragment extends BaseAppFragment {


    WhiteBroadView whiteBroadView;

    @BindView(R2.id.oto_f_board)
    FrameLayout f_board;

    @BindView(R2.id.oto_lin_insert)
    LinearLayout lin_insert;
    @BindView(R2.id.oto_tv_progress)
    TextView tv_progress;

    String identity;

    Room room;

    @SuppressLint("ValidFragment")
    public StudyWhiteBroadFragment(WhiteBroadView whiteBroadView, Room whiteBoardRoom) {

        this.whiteBroadView = whiteBroadView;

        this.room = whiteBoardRoom;

        showLog("WhiteBoardFragment");

    }

    @Override
    protected void onCreateView(View view, Bundle savedInstanceState) {

        identity = SharedPreferenceManager.getInstance(getActivity()).getUserCache().getUserIdentity();

        f_board.removeAllViews();
        f_board.addView(whiteBroadView);

        showLog("onCreateView" + "Width:" + f_board.getWidth() + "Height:" + f_board.getHeight());


//        setBoradTool(Appliance.PENCIL);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_room_white;
    }


    @Override
    public void onStop() {
        super.onStop();

        f_board.removeAllViews();

    }

    @Override
    public void onResume() {
        super.onResume();
        showLog("onResume" + "Width:" + f_board.getWidth() + "Height:" + f_board.getHeight());

        refreshRoom();

    }

    public void refreshRoom() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (room != null) {
                    showLog("刷新白板");
                    room.refreshViewSize();

                }
            }
        }, 1000);
    }

    public void setRoom(Room room) {

        this.room = room;

        refreshRoom();

    }

}
